package com.shj.em.biz.company.service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.shj.em.biz.company.dto.CompanySearchDTO;
import com.shj.em.biz.company.entity.Company;
import com.shj.em.biz.company.mapper.CompanyMapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;

import com.baomidou.mybatisplus.plugins.Page;
import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;


/**
 * 客户信息 服务实现类
 *
 * @author Shen Huang Jian
 * @since 2018-07-05
 */
@Service
@Transactional
public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, Company> implements CompanyService {

    @Autowired
    CompanyMapper companyMapper;

    public Page<Company> queryCompanyPage(CompanySearchDTO searchDTO){
        Page<Company> page = new Page<>(searchDTO.getPageNo(), searchDTO.getPageSize());
        List<Company> list = companyMapper.queryCompanyPage(page, searchDTO);
        return page.setRecords(list);
    }

    public List<Company> getAllCustomers(){
        Wrapper<Company> wrapper = new EntityWrapper<>();
        wrapper.where("ctype={0}", 1)
                .andNew("del_flag={0}", 0);
        return companyMapper.selectList(wrapper);
    }

    public List<Company> getCustomersBySellMan(String userId){
        //暂时可以看到所有客户
        return getAllCustomers();
        //return companyMapper.getCustomersBySellMan(userId);
    }

    public List<Company> getAllSupplies(){
        Wrapper<Company> wrapper = new EntityWrapper<>();
        wrapper.where("ctype={0}", 2)
                .andNew("del_flag={0}", 0);
        return companyMapper.selectList(wrapper);
    }

    public long insertCompany(Company company){
        companyMapper.insert(company);
        return company.getId();
    }
}
